home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / make / icmake-6.000 / icmake-6 / icmake / exec / execmd.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-08  |  1.8 KB  |  72 lines

  1. /*
  2. \funcref{execmd}{char $**$execmd (\params)}
  3.     {
  4.         {char} {**cmd} {{\em argv}-like array of command}
  5.         {int} {mode} {execution mode}
  6.     }
  7.     {spawn\_err(), error()}
  8.     {fun\_exec()}
  9.     {execmd.c}
  10.     {
  11.  
  12.         This function is called from {\em fun\_exec()} to execute a command.
  13.         The command is held in the {\em argv}-like array {\em cmd}. The same
  14.         array is returned, since {\em execmd()} may have to resize it to add a
  15.         command tail.
  16.  
  17.         The return register is set to the exit status of the program.
  18.  
  19.         The maker aborts when:
  20.  
  21.         \begin{itemize}
  22.  
  23.             \item the indicated program cannot not be executed,
  24.  
  25.             \item the indicated program can be executed but returns a
  26.             non-zero exit status while the execution mode allows checking.
  27.  
  28.         \end{itemize}
  29.  
  30.         {\bf Note that} the strings pointed to by the {\em cmd} array are not
  31.         freed.
  32.     }
  33. */
  34.  
  35. #include "icm-exec.h"
  36.  
  37. char **execmd (cmd, mode)
  38. char **cmd;
  39. int mode;
  40. {
  41.     register int
  42.         i,
  43.         ret;                    /* exit status */
  44.  
  45.     if (strlen (cmdtail))            /* add cmd tail */
  46.         cmd = addcmd (cmd, cmdtail);
  47.  
  48.     if (echo)                    /* re-echo if requested */
  49.     {
  50.         for (i = 0; cmd [i]; i++)
  51.             printf ("%s ", cmd [i]);
  52.         putchar ('\n');
  53.     }
  54.     fflush (stdout);
  55.     
  56. #ifdef MSDOS    
  57.     _heapmin ();                /* max memory under DOS */
  58. #endif    
  59.  
  60.                         /* try to execute */
  61.     ret = _spawnvp (P_WAIT, cmd [0], (const char **) cmd);
  62.     
  63.                             /* if non-zero return and */
  64.     if (ret && P_CHECKMODE (mode))        /* if checking requested.. */
  65.         error ("execute - program indicates failure (status %d)", ret);
  66.  
  67.     reg.type = e_int;                /* return exit status */
  68.     reg.vu.intval = ret;            /* as e_int */
  69.  
  70.     return (cmd);
  71. }
  72.